/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.biggrid.plier.event;

/**
 *
 * @author vledemo
 */
import java.util.Date;
import javax.jdo.annotations.PersistenceCapable;
import nl.biggrid.plier.opm.OPMGraph;
/**
 * This class represents an event occurred on a given host at
 * a given timestamp. It has a description, category, code,
 * level and a source.
 */
@PersistenceCapable
public class Event implements java.io.Serializable {//, TimeStampable {

    /**
     * Field _dbid.
     */
    private int _id; // 'Event specific ID',
    private String _identification; //'Identification of the module or workflow (Id)',
    private String _description; //'Custom message',
    private String _source; //'Name of the component plus "id" if possible',
    private String _sourceName; //'Name of the component source of event',
    private String _host; //'URL of the site',
    private Date _timestamp; //'Database Timestamp of event',
    private int _level; // 'Event level (0 - Trace, 1 - Debug, 2 - Information, 3 - Warning, 4 - Error, and 5 - Fatal)',
    private int _code; //'Code for the developers',
    private int _category; //'Category (0 - Workflow, 1 - Service/Module, 2 - Other)',
    /**
     * Field timestamp for Castor to be able to update persistent OPMGraph objects.
     */
    //private long timestamp;
    /**
     * Field graph.
     */
    private OPMGraph graph;

    /**
     * Returns the event object as a string.
     */
    @Override
    public String toString() {
        return getClass().getName() + "(" + _id + "::" + _host + "::" + _source + ")";
    }

    /**
     * Returns a copy of this event.
     *
     * @return a copy of this event.
     */
    public Event getNewCopy() {
        Event toReturn = new Event();

        toReturn.setId(this.getId());
        toReturn.setHost(this.getHost());
        toReturn.setDescription(this.getDescription());
        toReturn.setIdentification(this.getIdentification());
        toReturn.setSource(this.getSource());
        toReturn.setCategory(this.getCategory());
        toReturn.setCode(this.getCode());
        toReturn.setLevel(this.getLevel());
        toReturn.setTimestamp(this.getTimestamp());

        return toReturn;
    }

    /**
     * Sets the ID of this event.
     *
     * @param id the ID to set.
     */
    public void setId(int id) {
        this._id = id;
    }

    /**
     * Returns the ID of this event.
     *
     * @return the ID of this event.
     */
    final public int getId() {
        return this._id;
    }

    /**
     * Sets the host of this event.
     *
     * @param host the host to set.
     */
    public void setHost(String host) {
        _host = host;
    }

    /**
     * Returns the host of this event.
     *
     * @return the host of this event.
     */
    public String getHost() {
        return _host;
    }

    /**
     * Sets the description of this event.
     *
     * @param description the description to set.
     */
    public void setDescription(String description) {
        if (description.length() > 253) {
            _description = description.substring(0, 253);
        } else {
            _description = description;
        }
    }

    /**
     * Returns the description of this event.
     *
     * @return the description of this event.
     */
    public String getDescription() {
        return _description;
    }

    /**
     * Sets the identification of this event.
     *
     * @param identification the identification to set.
     */
    public void setIdentification(String identification) {
        _identification = identification;
    }

    /**
     * Returns the identification of this event.
     *
     * @return the identification of this event.
     */
    public String getIdentification() {
        return _identification;
    }

    /**
     * Sets the source of this event.
     *
     * @param source the source to set.
     */
    public void setSource(String source) {
        _source = source;
    }

    /**
     * Returns the source of this event.
     *
     * @return the source of this event.
     */
    public String getSource() {
        return _source;
    }

    /**
     * Sets the source of this event.
     *
     * @param source the source to set.
     */
    public void setSourceName(String sourceName) {
        _sourceName = sourceName;
    }

    /**
     * Returns the source of this event.
     *
     * @return the source of this event.
     */
    public String getSourceName() {
        return _sourceName;
    }

    /**
     * Sets the category of this event.
     *
     * @param category the category to set.
     */
    public void setCategory(int category) {
        _category = category;
    }

    /**
     * Returns the category of this event.
     *
     * @return the category of this event.
     */
    public int getCategory() {
        return _category;
    }

    /**
     * Sets the code of this event.
     *
     * @param code the code to set.
     */
    public void setCode(int code) {
        _code = code;
    }

    /**
     * Returns the code of this event.
     *
     * @return the code of this event.
     */
    public int getCode() {
        return _code;
    }

    /**
     * Sets the level of this event.
     *
     * @param type the level to set.
     */
    public void setLevel(int type) {
        _level = type;
    }

    /**
     * Returns the level of this event.
     *
     * @return the level of this event.
     */
    public int getLevel() {
        return _level;
    }

    /**
     * Sets the timestamp of this event.
     *
     * @param timestamp the timestamp to set.
     */
    public void setTimestamp(Date timestamp) {
        _timestamp = timestamp;
    }

    /**
     * Returns the timestamp this event occurred.
     *
     * @return The timestamp this event occurred.
     */
    public Date getTimestamp() {
        return _timestamp;
    }

    /**
     * Sets the OPM graph this event belongs to.
     *
     * @param graph the OPM graph this event belongs to.
     */
    public void setGraph(OPMGraph graph) {
        this.graph = graph;
    }

    /**
     * Returns the OPM graph this event belongs to.
     *
     * @return the value of the OPM graph this event belongs to.
     */
    public OPMGraph getGraph() {
        return graph;
    }

}